package htmlbrowser.domtree;

import javax.swing.text.html.HTML;
import javax.swing.text.AttributeSet;

import java.util.Map;
import java.util.HashMap;
import java.util.Enumeration;

public class HTMLDOMTreeNode {
	public HTML.Tag tag;
	public AttributeSet attr;
	
	public HTMLDOMTreeNode(HTML.Tag tag, AttributeSet attr) {
		this.tag = tag;
		this.attr = attr.copyAttributes();
	}
	
	public String toString() {
		return tag.toString() + " (" + attr.getAttributeCount() + ")";
	}
	
	public Map<String,String> getAttributesMap() {
		Map<String,String> attrMap = new HashMap<String, String>();
		
		Enumeration attrEnum = attr.getAttributeNames();
		
		while (attrEnum.hasMoreElements()) {
			String name = attrEnum.nextElement().toString();
			attrMap.put(name, attr.getAttribute(name).toString());
		}
		
		return attrMap;
	}
}
